"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var KeRouter = function () {
    function KeRouter() {
        _classCallCheck(this, KeRouter);

        this.data = [];
        this.curr = 0;
        this.$options = null;
    }

    _createClass(KeRouter, [{
        key: "group",
        value: function group(options, func) {
            this.curr = this.data.length;
            this.$options = options;
            func();
            this.$options = null;
        }
    }, {
        key: "reg",
        value: function reg(rule, component) {
            var name = void 0;
            if (Array.isArray(rule)) {
                name = rule[0];
                rule = rule[1];
            } else {
                name = rule;
            }
            var r = {
                name: name,
                path: rule,
                component: component
            };
            var s = this.data.push(r);
            this.curr = s - 1;
            if (this.$options) {
                // console.log('路由分组配置', this.$options)
                this.data[this.curr].meta = Object.assign({}, this.data[this.curr].meta, this.$options);
            }
            return this;
        }
    }, {
        key: "meta",
        value: function meta(obj) {
            this.data[this.curr].meta = Object.assign({}, this.data[this.curr].meta, obj);
            return this;
        }
    }, {
        key: "children",
        value: function children(call) {
            var route = new KeRouter();
            call(route);
            this.data[this.curr].children = route.data;
            return this;
        }
    }]);

    return KeRouter;
}();

exports.default = KeRouter;